Crate arrow_ord

source ·
Expand description

Arrow ordering kernels

Sort RecordBatch

let a: ArrayRef = Arc::new(Int32Array::from(vec![1, 2, 3, 4]));
let b: ArrayRef = Arc::new(StringArray::from(vec!["b", "a", "e", "d"]));
let batch = RecordBatch::try_from_iter(vec![("a", a), ("b", b)]).unwrap();

// Sort by column 1
let indices = sort_to_indices(batch.column(1), None, None).unwrap();

// Apply indices to batch columns
let columns = batch.columns().iter().map(|c| take(&*c, &indices, None).unwrap()).collect();
let sorted = RecordBatch::try_new(batch.schema(), columns).unwrap();

let col1 = sorted.column(0).as_primitive::<Int32Type>();
assert_eq!(col1.values(), &[2, 1, 4, 3]);

Modules

  • Comparison kernels for Arrays.
  • Contains functions and function factories to compare arrays.
  • Defines partition kernel for ArrayRef
  • Defines sort kernel for ArrayRef